package com.sz.web.jackson.databind;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Date序列化规则
 *
 * @author: yxl
 * 2025-07-23
 */
public class DateSerializer extends JsonSerializer<Date> {
    public static final DateSerializer INSTANCE = new DateSerializer();
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        gen.writeString(DATE_FORMAT.format(date));
    }
}
